/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package component;

import ddf.minim.AudioPlayer;
import processing.core.PApplet;

/**
 *
 * @author biron
 */
public class ButtonPlay extends AButton
{
  private boolean       _play;
  private boolean       _invert;
  private AudioPlayer   _player;
  
  public ButtonPlay(int x, int y, int hw, int hh, PApplet app, AudioPlayer player) 
  { 
    super(x, y, hw, hh, app); 
    _play = true;
    _player = player;
  }
  
  // code to handle playing and pausing the file
  public void mousePressed()
  {
    if ( pressed() )
    {
      _invert = true;
      if ( _player.isPlaying() ) 
      {
        _player.pause();
        _play = true;
      }
      else
      {
        _player.loop();
        _play = false;
      }
    }
  }
  
  public void mouseReleased()
  {
    _invert = false;
  }
  
  // _play is a boolean value used to determine what to draw on the button
  public void update()
  {
    if ( _player.isPlaying() ) _play = false;
    else _play = true;
  }
  
  public void draw()
  {
    if ( _invert )
    {
      _app.fill(255);
      _app.stroke(0);
    }
    else
    {
      _app.noFill();
      _app.stroke(255);
    }
    
    _app.rect(x - hw, y - hh, hw*2, hh*2);
    if ( _invert )
    {
      _app.fill(0);
      _app.stroke(255);
    }
    else
    {
      _app.fill(255);
      _app.noStroke();
    }
    if ( _play )
    {
      _app.triangle(x - hw/3, y - hh/2, x - hw/3, y + hh/2, x + hw/2, y);
    }
    else
    {
      _app.rect(x - hw/3, y - hh/2, hw/4, hh);
      _app.rect(x + hw/8, y - hh/2, hw/4, hh);
    }
  }
}
